#region Copyright RenGuiYou. All rights reserved.

//=====================================================
// PandoraFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================

#endregion

using System.IO;
using NeatlyEditor;
using Pandora;
using PandoraEditor.Window;
using UnityEditor;
using UnityEngine;

namespace PandoraEditor
{
    public static class PdrMenuOptions
    {
        [MenuItem("Pandora/打开Protobuf", false, 1)]
        public static void OpenProtobuf()
        {
            PdrFileUtil.OpenFolder(UserSetting.ProtocolSetting.proto_repo);
        }

        [MenuItem("Pandora/Open Log Explorer", false, 100)]
        public static void OpenLog()
        {
            LogFile.OpenLogExplorer();
        }

        [MenuItem("Pandora/Open Persistent Data", false, 101)]
        public static void OpenPersistentData()
        {
            PdrFileUtil.OpenFolder(Application.persistentDataPath);
        }

        [MenuItem("Pandora/Open Project Path", false, 102)]
        public static void OpenProjectPath()
        {
            EditorUtility.RevealInFinder(Application.dataPath);
        }

        [MenuItem("Pandora/Open Android Path", false, 103)]
        public static void OpenAndroidPath()
        {
            PdrFileUtil.OpenFolder(NeatlyEditorConfig.PATH_ANDROID);
        }

        [MenuItem("Pandora/Open iOS Path", false, 103)]
        public static void OpenIOSPath()
        {
            PdrFileUtil.OpenFolder(NeatlyEditorConfig.PATH_IOS);
        }

        [MenuItem("Pandora/Open Win64 Path", false, 103)]
        public static void OpenWin64Path()
        {
            PdrFileUtil.OpenFolder(NeatlyEditorConfig.PATH_WIN64);
        }

        [MenuItem("Pandora/Open Export Bundle", false, 104)]
        public static void OpenExportBundle()
        {
            PdrFileUtil.OpenFolder(NeatlyEditorConfig.PATH_EXPORT_BUNDLE);
        }

        [MenuItem("Pandora/打开内网资源", false, 201)]
        public static void OpenLocalServerAsset()
        {
            PdrFileUtil.OpenFolder(BuildSetting.LocalServerSetting.path_asset);
        }

        [MenuItem("Pandora/打开内网包", false, 202)]
        public static void OpenLocalServerPackage()
        {
            PdrFileUtil.OpenFolder(BuildSetting.LocalServerSetting.path_package_svn);
        }

        [MenuItem("Pandora/删除空文件夹", false, 108)]
        public static void DeleteEmptyFolder()
        {
            DeleteFolderEmpty(Application.dataPath);
            AssetDatabase.Refresh();
            Debug.Log("空文件夹删除完成...");
        }

        [MenuItem("Pandora/Project Builder Window", false, 300)]
        public static void OpenProjectBuilderWindow()
        {
            BuilderWindow.CreateWindow();
        }

        [MenuItem("Pandora/Preferences Window", false, 301)]
        public static void OpenPreferencesWindow()
        {
            PreferencesWindow.CreateWindow();
        }

        [MenuItem("Pandora/Open pandora Window", false, 401)]
        public static void OpenPandoraWindow()
        {
            PdrWindow.Open();
        }

        [MenuItem("Pandora/删除多余图集", false, 501)]
        public static void DeleteEmptyAtlas()
        {
            DeleteFolderEmpty(Application.dataPath);
            AtlasExtend.ClearEmptyAtlas();
            Debug.Log("图集清理完毕.");
        }

        [MenuItem("Pandora/打包所有图集", false, 502)]
        public static void MakeAllAtlas()
        {
            DeleteEmptyAtlas();
            AtlasMaker.MakeAllUIAtlas();
        }

        [MenuItem("Pandora/打包所有特效图集", false, 601)]
        public static void MakeAllEffectAtlas()
        {
            EffectAtlasMaker.ExecuteWrapEffectAtlas();
        }

        [MenuItem("Pandora/生成所有spine预置", false, 602)]
        public static void CreateAllSpinePrefabs()
        {
            SpineMaker.MakeSpinePrefab();
        }

        [MenuItem("Pandora/创建GlobalPrefabPool", false, 603)]
        public static void CreateGlobalPrefabPool()
        {
            GlobalPrefabPoolTool.GenerateGlobalPrefabPol();
        }
        
        [MenuItem("Pandora/刷新预制GUID", false, 1003)]
        public static void UpdateHierarchyDepend()
        {
            AtlasExtend.UpdateHierarchyDepend();
        }

        private static void DeleteFolderEmpty(string path)
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            if (dir.GetFileSystemInfos().Length == 0)
            {
                PdrFileUtil.DeleteDirectory(path);
                PdrFileUtil.DeleteFile(path + ".meta");
                return;
            }

            foreach (var directoryInfo in dir.GetDirectories())
            {
                DeleteFolderEmpty(directoryInfo.FullName);
            }
        }
    }
}